package open.kodandroid.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import open.kodandroid.R;

public class PreLoginActivity extends Activity {

    private static final int LOGINID = 1;
    private EditText mServerView;


    private void startLoginActivity(String serveraddr) {
        Intent i = new Intent(this, LoginActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        i.putExtra("serverurl", serveraddr);
        this.startActivityForResult(i, LOGINID);
    }


    private void saveServerAddr(String addr){

    }

    private void getServerAddr(String addr){

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pre_login_layout);

        Button b = findViewById(R.id.login);
        mServerView = findViewById(R.id.server_addr);




        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {



                String serveraddr = mServerView.getText().toString();
                if(!serveraddr.startsWith("http")){
                    return;
                }else{
                    saveServerAddr(serveraddr);
                }
                startLoginActivity(serveraddr);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
    }
}
